<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>截取替换字符串</title>
</head>

<body>
  <h2>http://localhost/</h2>
  截取替换字符串
  <script>
    // const URL = "http://localhost"
    // const m = "https://midwayjs.org/666666"
    const URL = "http://172.18.110.24:8090/";
    const m = "http://localhost:8090/iserver/services/data-ShuiYouJiTuanXinZongBuDaLou-12/rest";
    // const index = find(m,":",1)
    const index = m.indexOf("iserver")
    const num = m.substring(index,0)
    const url = m.replace(num,URL).replace("data","3D")
    const xxx = url.split("").splice(-8,3).join("")
    const dfdf = url.replace(xxx,"")
    const result = dfdf +"/realspace/datas/税友集团新总部大楼/config"
    // const xxx = m.splice(-6,3)
    console.log("原始地址",m);
    console.log("替换后地址",url);
    console.log("替换后地址",dfdf);
    console.log("截取数字",xxx);
    console.log("最终的",result);


    function find(str,cha,num){
      // debugger
    // 第一次出现“/”的索引
    const x = str.indexOf(cha);
    console.log(x);
    for(let i = 0; i < num; i++){
        const y = str.indexOf(cha,x+1);
        console.log(y);
        return y;
    }
    // return y;
}
  </script>
</body>

</html>